package book.nettyinaction.ch10;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

/**
 * 代码清单 10-2 ToIntegerDecoderV2 类扩展了 ReplayingDecoder
 */
public class ToIntegerDecoderV2 extends ReplayingDecoder<Void> {

    /**
     *
     * @param ctx
     * @param in    传入的`ByteBuf`是`ReplayingDecoderByteBuf`
     * @param out
     * @throws Exception
     */
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        // 从入站ByteBuf中读取一个int，并将其添加到解码消息的List中
        out.add( in.readInt() );
    }
}
